//
//  ZAction.m
//  SlashEM
//
//  Created by dirk on 1/13/10.
//  Copyright 2010 Dirk Zimmermann. All rights reserved.
//

//  This file is part of Slash'EM.
//
//  Slash'EM is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, version 2 of the License only.
//
//  Slash'EM is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Slash'EM.  If not, see <http://www.gnu.org/licenses/>.

#import "ZAction.h"

@implementation ZAction

@synthesize title;
@synthesize sender;

+ (id)actionWithTitle:(NSString *)t target:(id)targ action:(SEL)a argument:(id)arg {
	return [[[self alloc] initWithTitle:t target:targ action:a argument:arg] autorelease];
}

+ (id)actionWithTitle:(NSString *)t target:(id)targ action:(SEL)a {
	return [[[self alloc] initWithTitle:t target:targ action:a] autorelease];
}

- (id)initWithTitle:(NSString *)t target:(id)targ action:(SEL)a argument:(id)arg {
	if (self = [super init]) {
		title = [t copy];
		target = [targ retain];
		action = a;
		argument = [arg retain];
	}
	return self;
}

- (id)initWithTitle:(NSString *)t target:(id)targ action:(SEL)a {
	return [self initWithTitle:t target:targ action:a argument:nil];
}

- (void) dealloc {
	[title release];
	[target release];
	[super dealloc];
}

#pragma mark Action

- (void)invoke:(id)s {
	self.sender = s;
	id arg = argument ? argument:self;
	[target performSelector:action withObject:arg];
}

@end
